﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Quartz;
using log4net;
using Quartz.Impl;
namespace LuceneNetServices.QuzrtzNetCommon
{
    public static class SchedulerManager
    {
        private static IScheduler scheduler;
        private static readonly object lockObj1 = new object();
        private static readonly object lockObj2 = new object();
        private static readonly object lockObj3 = new object();
        private static ISchedulerFactory factory;
        private static IJobListener jobListener;
        /// <summary>
        /// 控制器工厂
        /// </summary>
        /// <returns></returns>
        public static ISchedulerFactory GetSchedulerFactory()
        {
            if (factory == null)
            {
                lock (lockObj1)
                {
                    if (factory == null)
                    {
                        factory = new StdSchedulerFactory();
                    }
                }
            }
            return factory;
        }
        /// <summary>
        /// 获取调度器
        /// </summary>
        /// <returns></returns>
        public static IScheduler GetScheduler()
        {
            if (scheduler == null)
            {
                lock (lockObj2)
                {
                    if (scheduler == null)
                    {
                        scheduler = GetSchedulerFactory().GetScheduler();
                    }
                }
            }
            return scheduler;
        }
        /// <summary>
        /// 任务监视器
        /// </summary>
        /// <returns></returns>
        public static IJobListener GetJobListener()
        {
            if (jobListener == null)
            {
                lock (lockObj3)
                {
                    if (jobListener == null)
                    {
                        jobListener = new CustomJobListener();
                    }
                }
            }
            return jobListener;
        }


    }
}
